<?php
/**
 * $Author: BEESSHOP $
 * ============================================================================
 * ============================================================================
 */
namespace app\usermodule\controllers;

use app\models\MemberRecorder;
use app\models\SetRecorder;
use yii\web\Controller;

class BaseController extends Controller{
    public $enableCsrfValidation = false;
    public $user;

    public function beforeAction($action)
    {
        $token = \Yii::$app->request->post('token');
        $user_model = MemberRecorder::find()->where('token=:token',[':token' => $token])->one();
        if(empty($user_model)){
            $result = ['result'=>'login_error','data'=>'请先登录'];
            echo json_encode($result);
            return false;
        }
        if($user_model->status){
            $result = ['result'=>'login_error','data'=>'会员已被锁定，无法操作，请联系管理员处理'];
            echo json_encode($result);
            return false;
        }
        $this->user = $user_model;
        $set_model = SetRecorder::find()->where('set_type=1')->one();
        $set_param = empty($set_model->content)?[]:json_decode($set_model->content,true);
        $param = \Yii::$app->params;
        $param = array_merge($set_param,$param);
        \Yii::$app->params=$param;
        return parent::beforeAction($action); // TODO: Change the autogenerated stub
    }
}
